﻿using Prism.Mvvm;
using FrameWork.Core.China;
using System.Collections.Generic;
using FrameWork.Core.Adapter.Device;

namespace FrameWork.Core.Chain.Entitys
{
    /// <summary>
    /// 流程数据基类
    /// </summary>
    public class ProcessDataBase : BindableBase
    {
        private readonly object m_lock = new object();
        /// <summary>
        /// 读书证卡号
        /// </summary>
        public string ReaderNo { get; set; }
        /// <summary>
        /// 提示信息
        /// </summary>
        public string Message { get; set; }
        /// <summary>
        /// 实际执行顺序号
        /// </summary>
        public int Index { get; set; } = 1;
        /// <summary>
        /// 当前执行步骤号
        /// </summary>
        public IProcessNode CurrentNode { get; set; }
        /// <summary>
        /// 运行节点号
        /// </summary>
        public long StartOrder { get; set; }
        /// <summary>
        /// 设备编码
        /// </summary>
        public string DeviceId { get; set; }
        /// <summary>
        /// 第一个采样数据
        /// </summary>
        public NetWorkResult<BaseNetWorkWrap> FirstFrameData { get; set; }
        /// <summary>
        /// 第二个采样数据
        /// </summary>
        public NetWorkResult<BaseNetWorkWrap> SecondFrameData { get; set; }
        /// <summary>
        /// 跳转时清空数据
        /// </summary>
        /// <param name="sampData"></param>
        public void ClearSampData()
        {
            lock (m_lock)
            {
                this.SecondFrameData = null;
                this.FirstFrameData = null;
            }
        }
        /// <summary>
        /// 锁定数据
        /// </summary>
        /// <param name="sampData"></param>
        public void PutSampData(NetWorkResult<BaseNetWorkWrap> sampData)
        {
            lock (m_lock)
            {
                this.SecondFrameData = sampData;
                if (this.FirstFrameData == null)
                    this.FirstFrameData = sampData;
            }
        }
        /// <summary>
        /// 交换数据
        /// </summary>
        public void ExchangeSampData()
        {
            lock (m_lock)
            {
                if (this.SecondFrameData == null)
                {
                    return;
                }
                this.FirstFrameData = this.SecondFrameData;
                this.SecondFrameData = null;
            }
        }
        /// <summary>
        /// 数据字典
        /// </summary>
        public Dictionary<string, object> Map = new Dictionary<string, object>();
    }
}